/**
*	Group: Y1
*	The MenuPanel class reders the menu onto the screen. Its responsibilities include reading in all the images and logos, and writing them
*	onto the menu screen. The class invokes the background music, renders the game logo, and the four buttons (Play, Instructions, Credits, Exit)
* 	and also paints the background black.
*	@author Jessica Newman
* 	@author Rahul Kapadia
*/
package lightspeed.Media.Graphics;
import lightspeed.Media.Audio.SoundPlayer;
import javax.swing.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java.io.*;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import sun.audio.*;

public class MenuPanel extends JPanel
{
	//initialize images
	/**
	*	Initialize the BufferedImage which will represent the  play button on the menu when not hovered by mouse
	*/
	BufferedImage playInactive = null;
	/**
	*	Initialize the BufferedImage which will represent the  play button on the menu when hovered by mouse
	*/
	BufferedImage playActive = null;
	/**
	*	Initialize the BufferedImage which will represent the Exit button on the menu when not hovered by mouse
	*/
	BufferedImage exitInactive = null;
	/**
	*	Initialize the BufferedImage which will represent the Exit button on the menu when hovered by mouse
	*/
	BufferedImage exitActive = null;
	/**
	*	Initialize the BufferedImage which will represent the logo for LightSpeed2000
	*/
	BufferedImage logo = null;
	/**
	*	Boolean variable to determine wheather the mouse hovers over the play button
	*/
	public static boolean paActive=false;
	/**
	*	Boolean variable to determine wheather the mouse hovers over the exit button
	*/
	public static boolean exActive=false;
	//setting the x and y coordinates of the top left corner of each image
	/**
	*	Sets the x coordinate of the top left corener of the LightSpeed2000 logo image
	*/
	public static int logoX=(int)((50.0/100.0)*(double)WindowManager.WINDOW_WIDTH)-400;
	/**
	*	Sets the y coordinate of the top left corner of the LightSpeed2000 logo image
	*/
	public static int logoY=(int)((10.0/100.0)*(double)WindowManager.WINDOW_HEIGHT);
	/**
	*	Sets the x coordinate of the top left corner of the Play Button image
	*/
	public static int playX=logoX+40;
	/**
	*	Sets the y coordinate of the top left corner of the Play Button image
	*/
	public static int playY=(int)((70.0/100.0)*(double)WindowManager.WINDOW_HEIGHT);
	/**
	*	Sets the x coordinate of the top left corner of the Exit Button image
	*/
	public static int exitX=logoX+520;
	/**
	*	Sets the y coordinate of the top left corner of the Exit Button image
	*/
	public static int exitY=playY;
	
	
	/**
	*	Constructor: creates an instance of MenuPanel
	*	When this constructor is invoked, the Menu screen is rendered as all the image files that represent the
	*	button and logo for the menu are read in and drawn to the menu screen. Also an instance of s SouinPlayer is created 
	*	in order to invoke the background menu music.
	*/
	public MenuPanel()
	{
		//Sets a plain black background
		setLayout(null);
		setBackground(Color.black);
		
		
		try
		{
			//creates a bunch of images
			playInactive=ImageIO.read(new File("images/connPlay1.png"));
			playActive=ImageIO.read(new File("images/connPlay2.png"));
			exitInactive=ImageIO.read(new File("images/exit1.png"));
			exitActive=ImageIO.read(new File("images/exit2.png"));
			logo=ImageIO.read(new File("images/logocredits.png"));
		}
		catch(IOException e)
		{
			//throws an IOexception if the image paths are invalid
			System.out.println("IOException");
		}
		
		
		//starts up the menu music
	
			SoundPlayer menuMusic = new SoundPlayer("audio/menu.wav");
			menuMusic.playloop();
		
		
	
	}
	/**
	*	Creates the images at the specified coordinates.
	*	drawImage function takes the image, x coordinate, y coordinate, and an ImageObserver as parameters
	*	@param g Graphics object in order to draw the images onto the menu screen
	*/
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.drawImage(logo,logoX,logoY,null);
		if(paActive==false)
			g.drawImage(playInactive,playX,playY,null);
		else
			g.drawImage(playActive,playX,playY,null);
		if(exActive==false)
			g.drawImage(exitInactive,exitX,exitY,null);
		else
			g.drawImage(exitActive,exitX,exitY,null);
	}
	/**
	*	helper method to call repaint from static context
	*/
	public void paintPanel()
	{
		repaint();
	}
	
	//private classes//
}
